package com.dui;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public class Dui {
    int x;
    int y;
    int width;
    int speed;
    int score;
    int level;

    int state=0;//0 1

    Image duiImg;
    Image[] duiImgs = new Image[4];


    public Dui(){
        for (int i = 0; i<duiImgs.length;i++){
            duiImgs[i] = new ImageIcon("img/dui"+i+".png").getImage();
        }
        if(state==0){
            duiImg = duiImgs[0];
        }
        else{
            duiImg = duiImgs[2];
        }

        this.x = 50;
        this.y = 70;
        this.score = 0;
        this.speed = 40;

    }

    int index = 0;
    public void step() {
        if(state==0){
            duiImg =duiImgs[index++/10%2];
        }else{
            duiImg =duiImgs[index++/10%2+2];
        }

    }
    //吃到蟑螂
    public boolean eatBeetle(Beetle beetle){
        int dx1 = this.x;
        int dy1 = this.y;
        int dx2 = this.x + this.duiImg.getWidth(null);
        int dy2 = this.y + this.duiImg.getHeight(null)/3;

        int bx1 = beetle.x;
        int by1 = beetle.y;
        int bx2 = beetle.x+beetle.beetleImg.getWidth(null);
        int by2 = beetle.y+beetle.beetleImg.getHeight(null);
        if(dx1<=bx1&&dy1<=by1&&dx2>=bx2&&dy2>=by2){
            return true;
        }




        return false;
    }


}
